package com.resource.studentmanage.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.resource.common.utils.PageUtils;
import com.resource.common.utils.Query;
import com.resource.studentmanage.entity.TStudentExamEntity;
import com.resource.studentmanage.entity.TStudentWorkEntity;
import com.resource.studentmanage.mapper.TStudentWorkDao;
import com.resource.studentmanage.service.TStudentWorkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;



@Service
@Slf4j
public class TStudentWorkServiceImpl extends ServiceImpl<TStudentWorkDao, TStudentWorkEntity> implements TStudentWorkService {

    @Override
    public void dealStudentWork(Map<String, String> map) {
        TStudentWorkEntity tStudentWorkEntity = new TStudentWorkEntity();
        tStudentWorkEntity.setStudentCode(map.get("studentCode"));
        tStudentWorkEntity.setStudentName(map.get("studentName"));
        tStudentWorkEntity.setWorkCode(map.get("workCode"));
        tStudentWorkEntity.setWorkName(map.get("workName"));
        tStudentWorkEntity.setWorkProgress("未完成");
        tStudentWorkEntity.setTeacherName(map.get("workAuditTeacherName"));
        this.saveOrUpdate(tStudentWorkEntity);
    }

    @Override
    public void submitStudentWork(Map<String, String> map) {
        log.error("开始修改学生作业信息");
        String studentCode = map.get("studentCode");
        String teacherName = map.get("teacherName");
        String messageContent = map.get("messageContent");
        TStudentWorkEntity one = this.getOne(new QueryWrapper<TStudentWorkEntity>().eq("student_code", studentCode).eq("teacher_name", teacherName
        ));
        if(!Objects.isNull(one)){
            one.setWorkProgress("已完成");
            one.setWorkRemark(messageContent);
            this.updateById(one);
            log.error("更新学习作业信息完成");
        }else{
            log.error("获取学生作业信息为空");
        }
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        int size = params.size();
        IPage<TStudentWorkEntity> page=new Page<>();
        if(size==4){
            String keys="";
            String param="";
            Set<String> strings = params.keySet();
            for (String key : strings) {
                keys=key;
                param=params.get(keys).toString();
            }
            page = this.page(
                    new Query<TStudentWorkEntity>().getPage(params),
                    new QueryWrapper<TStudentWorkEntity>().eq(keys,param)
            );
            return new PageUtils(page);
        }
        page = this.page(
                new Query<TStudentWorkEntity>().getPage(params),
                new QueryWrapper<TStudentWorkEntity>()
        );

        return new PageUtils(page);
    }

}